<template>
  <div class="pie-chart" :style="{width: width, height: height}"></div>
</template>
<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons')
  export default {
    name: 'PieChart',
    props: {
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '333px'
      }
    },
    data () {
      return {
        chart: null
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    methods: {
      initChart(){
        this.chart = echarts.init(this.$el)

        let option = option = {
          tooltip: {
            trigger: 'item'
          },
          legend: {
            left: 'center',
            textStyle: {
              color: '#fff'
            },
            itemWidth: 10,
            itemHeight: 10,
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              name: 'Access From',
              type: 'pie',
              radius: '50%',
              data: [
                { value: 1000, name: '车位1', itemStyle: {color: '#fe81ee'} },
                { value: 735, name: '车位2', itemStyle: {color: '#f4689f'} },
                { value: 580, name: '车位3', itemStyle: {color: '#fd624f'} },
                { value: 484, name: '车位4', itemStyle: {color: '#f39f02'} },
                { value: 300, name: '车位5', itemStyle: {color: '#05e480'} },
                { value: 48, name: '车位6', itemStyle: {color: '#02e4bb'} },
              ],
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        };
        this.chart.setOption(option)
      }
    }
  }
</script>